﻿using System.Collections.Generic;

namespace WordCloudGenerator.TextAnalyses.Processing
{
    public struct               Word : IWord
    {
        public string           Text { get; private set; }
        public int              Occurrences { get; private set; }

        public Word(KeyValuePair<string, int> textOccurrencesPair) : this(textOccurrencesPair.Key, textOccurrencesPair.Value)
        {
        }

        public Word(string text, int occurrences) : this()
        {
            this.Text = text;
            this.Occurrences = occurrences;
        }

        public void             SetOccurences(int occurences)
        {
            this.Occurrences = occurences;
        }

        public string           GetCaption()
        {
            return (string.Format("{0}\t{1}", this.Text, this.Occurrences));
        }

        public override string  ToString()
        {
            return (this.Text);
        }

        public int              CompareTo(IWord other)
        {
            return (this.Occurrences - other.Occurrences);
        }

        public static bool      operator ==(Word w1, Word w2)
        {
            if (w1.Text.CompareTo(w2.Text) == 0)
                return (true);
            return (false);
        }

        public static bool      operator !=(Word w1, Word w2)
        {
            if (w1.Text.CompareTo(w2.Text) == 0)
                return (false);
            return (true);
        }

        public override bool    Equals(object obj)
        {
            if (obj is Word)
                return (this == (Word)obj);
            return (false);
        }

        public override int     GetHashCode()
        {
            return (this.Text.GetHashCode()); // Unique hash for each Word.
        }
    }
}